<template>
   <div class="order-item">
        <div class="head">
          <span>下单时间：{{order.createTime}}</span>
          <span>订单编号：{{order.id}}</span>
          <span class="down-time" v-if="order.orderState===1">
            <i class="iconfont icon-down-time"></i>
            <b>付款截止:{{timeText}}</b>
          </span>
          <a href="javascript:;" class="del" v-if="[5,6].includes(order.orderState)" @click="$emit('on-delete',order.id)">删除</a>
        </div>
        <div class="body">
          <div class="column goods">
            <ul>
              <li v-for="goods in order.skus" :key="goods.id">
                <router-link class="image"  :to="`/product/${goods.spuId}`">
                  <img :src="goods.image" alt="" />
                </router-link>
                <div class="info">
                  <p class="name ellipsis-2">{{goods.name}}</p>
                  <p class="attr ellipsis">
                    <span>{{goods.propertyMainName}}{{goods.propertyValueName}}</span>
                    <span>{{goods.attrsText}}</span>
                  </p>
                </div>
                <div class="price">¥9.50</div>
                <div class="count">x1</div>
              </li>
            </ul>
          </div>
          <div class="column state">
            <p>{{orderStatus[order.orderState].label}}</p>
            <p v-if="order.orderState===3"><a href="javascript:;" class="green" @click="$emit('on-logistics',order)">查看物流</a></p>
            <p v-if="order.orderState===4"><a href="javascript:;" class="green">待评价</a></p>
            <p v-if="order.orderState===5"><a href="javascript:;" class="green">查看评价</a></p>
          </div>
          <div class="column amount">
            <p class="red">¥{{order.payMoney}}</p>
            <p>（含运费：¥{{order.postFee}}）</p>
            <p>{{order.payType===1 ? '在线支付':'货到付款'}}</p>
          </div>
          <div class="column action">
            <XtxButton type="primary" size="small" v-if="order.orderState===1" @click="$router.push(`/member/pay?orderId=${order.id}`)">立 即付款</XtxButton>
             <XtxButton type="primary" size="small" v-if="order.orderState===3" @click="$emit('on-confirmGoods',order)">确认收货</XtxButton>
            <p><a href="javascript:;" @click="$router.push(`/member/order/${order.id}`)">查看详情</a></p>
             <p><a href="javascript:;" v-if="order.orderState===1" @click="$emit('on-cancel',order)">取消订单</a></p>
            <p><a href="javascript:;" v-if="order.orderState===2">待发货</a></p>
            <p><a href="javascript:;" v-if="[2,3,4,5].includes(order.orderState)" @click="$router.push(`/member/checkout?orderId=${order.id}`)">再次购买</a></p>
            <p><a href="javascript:;" v-if="[4,5].includes(order.orderState)">申请售后</a></p>
          </div>
        </div>
      </div>
</template>

<script>
import {orderStatus} from "@/api/constants"
import {payCountDown} from "@/hook/index"
export default {
    
name:'OrderItem',
props:{
    order:{
        type:Object,
        default:()=>{}
    }
},
//将组件内自定义事件，放入此选项中，此代码无任何作用，纯属直观的展示此组件包含自定义事件
emit:['on-cancel','on-delete','on-confirmGoods','on-logistics'],
setup(props){
    const {start,timeText}=payCountDown()
    start(props.order.countdown)
   return {orderStatus,timeText}}
}

</script>

<style scoped lang="less">
.order-item {
  margin-bottom: 20px;
  border: 1px solid #f5f5f5;
  .head {
    height: 50px;
    line-height: 50px;
    background: #f5f5f5;
    padding: 0 20px;
    overflow: hidden;
    span {
      margin-right: 20px;
      &.down-time {
        margin-right: 0;
        float: right;
        i {
          vertical-align: middle;
          margin-right: 3px;
        }
        b {
          vertical-align: middle;
          font-weight: normal;
        }
      }
    }
    .del {
      margin-right: 0;
      float: right;
      color: #999;
    }
  }
  .body {
    display: flex;
    align-items: stretch;
    .column {
      border-left: 1px solid #f5f5f5;
      text-align: center;
      padding: 20px;
      > p {
        padding-top: 10px;
      }
      &:first-child {
        border-left: none;
      }
      &.goods {
        flex: 1;
        padding: 0;
        align-self: center;
        ul {
          li {
            border-bottom: 1px solid #f5f5f5;
            padding: 10px;
            display: flex;
            &:last-child {
              border-bottom: none;
            }
            .image {
              width: 70px;
              height: 70px;
              border: 1px solid #f5f5f5;
            }
            .info {
              width: 220px;
              text-align: left;
              padding: 0 10px;
              p {
                margin-bottom: 5px;
                &.name {
                  height: 38px;
                }
                &.attr {
                  color: #999;
                  font-size: 12px;
                  span {
                    margin-right: 5px;
                  }
                }
              }
            }
            .price {
              width: 100px;
            }
            .count {
              width: 80px;
            }
          }
        }
      }
      &.state {
        width: 120px;
        .green {
          color: @xtxColor;
        }
      }
      &.amount {
        width: 200px;
        .red {
          color: @priceColor;
        }
      }
      &.action {
        width: 140px;
        a {
          display: block;
          &:hover {
            color: @xtxColor;
          }
        }
      }
    }
  }
}
</style>